﻿using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace builderDesignMode.Configuration.Provider
{
    public class XmlConfigurationProvider : IxConfigurationProvider
    {
        public XmlConfigurationProvider() 
        {

        }

        public Dictionary<string,string> keyValuePairs = new Dictionary<string,string>();

        public FileConfigurationSourcex fileConfigurationSource { get; set; }

        public void AddXmlConfiguration() 
        {
            using (StreamReader file = File.OpenText("jsconfig.json"))
            {
                // 2、解析json文件
                using (JsonTextReader reader = new JsonTextReader(file))
                {
                    JObject jObject = (JObject)JToken.ReadFrom(reader);
                    var value = jObject["AllowedHosts"].ToString();

                    /* // json字典
                     IDictionary<string, string> keyValuePairs = new Dictionary<string, string>();
                     keyValuePairs.Add("AllowedHosts", value);*/

                    // 3、设值到Data
                    keyValuePairs.Add("AllowedHosts", value);
                }
            }
        }

        public string this[string key] {
            get { return keyValuePairs[key]; }
        }

        public string Get(string key) 
        {
            return keyValuePairs[key];
        }
    }
}
